package hn.sigit.model.ladm.spatialunit;

import java.io.Serializable;
import javax.persistence.*;
@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="LA_RequiredRelationshipSpatialUnit", schema="ladm_spatialunit")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorValue("LA_RequiredRelationship")
@IdClass(LA_RequiredRelationshipSpatialUnitPK.class)
public class LA_RequiredRelationshipSpatialUnit extends hn.sigit.model.ladm.special.VersionedObject implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long relSpatialUnits1La_spatialunitId;
	private long relSpatialUnits2La_spatialunitId;
	private byte relationship;
	private LA_SpatialUnit relSpatialUnits1La_spatialunit;
	private LA_SpatialUnit relSpatialUnits2La_spatialunit;

	public LA_RequiredRelationshipSpatialUnit() {
	}


	@Id
	@Column(name="LA_SpatialUnitID", nullable=false)
	@GeneratedValue(generator="la_requiredrelationshipspatialunit_id_gen")
	@org.hibernate.annotations.GenericGenerator(name="la_requiredrelationshipspatialunit_id_gen", strategy="foreign", parameters=@org.hibernate.annotations.Parameter(name="property", value="Id"))
	public long getRelSpatialUnits1La_spatialunitId() {
		return relSpatialUnits1La_spatialunitId;
	}
	protected void setRelSpatialUnits1La_spatialunitId(long value) {
		this.relSpatialUnits1La_spatialunitId = value;
	}
	
	@Id
	@Column(name="LA_SpatialUnitID2", nullable=false)
	@GeneratedValue(generator="la_requiredrelationshipspatialunit_id_gen2")
	@org.hibernate.annotations.GenericGenerator(name="la_requiredrelationshipspatialunit_id_gen2", strategy="foreign", parameters=@org.hibernate.annotations.Parameter(name="property", value="Id"))
	public long getRelSpatialUnits2La_spatialunitId() {
		return relSpatialUnits2La_spatialunitId;
	}
	protected void setRelSpatialUnits2La_spatialunitId(long value) {
		this.relSpatialUnits2La_spatialunitId = value;
	}
	
	@Column(name="Relationship", nullable=false)
	public byte getRelationship() {
		return relationship;
	}
	public void setRelationship(byte value) {
		this.relationship = value;
	}
	
	@PrimaryKeyJoinColumn
	@ManyToOne(targetEntity=LA_SpatialUnit.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
	@JoinColumns({ @JoinColumn(name="LA_SpatialUnitID2", referencedColumnName="ID") })
	public LA_SpatialUnit getRelSpatialUnits2La_spatialunit() {
		return relSpatialUnits2La_spatialunit;
	}
	public void setRelSpatialUnits2La_spatialunit(LA_SpatialUnit value) {
		this.relSpatialUnits2La_spatialunit = value;
	}
	
	@PrimaryKeyJoinColumn
	@ManyToOne(targetEntity=LA_SpatialUnit.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
	@JoinColumns({ @JoinColumn(name="LA_SpatialUnitID", referencedColumnName="ID") })
	public LA_SpatialUnit getRelSpatialUnits1La_spatialunit() {
		return relSpatialUnits1La_spatialunit;
	}
	public void setRelSpatialUnits1La_spatialunit(LA_SpatialUnit value) {
		this.relSpatialUnits1La_spatialunit = value;
	}

	public boolean equals(Object aObj) {
		if (aObj == this)
			return true;
		if (!(aObj instanceof LA_RequiredRelationshipSpatialUnit))
			return false;
		LA_RequiredRelationshipSpatialUnit la_requiredrelationshipspatialunit = (LA_RequiredRelationshipSpatialUnit)aObj;
		if (getRelSpatialUnits1La_spatialunit() == null) {
			if (la_requiredrelationshipspatialunit.getRelSpatialUnits1La_spatialunit() != null)
				return false;
		}
		else if (!getRelSpatialUnits1La_spatialunit().equals(la_requiredrelationshipspatialunit.getRelSpatialUnits1La_spatialunit()))
			return false;
		if (getRelSpatialUnits2La_spatialunit() == null) {
			if (la_requiredrelationshipspatialunit.getRelSpatialUnits2La_spatialunit() != null)
				return false;
		}
		else if (!getRelSpatialUnits2La_spatialunit().equals(la_requiredrelationshipspatialunit.getRelSpatialUnits2La_spatialunit()))
			return false;
		return true;
	}
	
	public int hashCode() {
		int hashcode = 0;
		if (getRelSpatialUnits1La_spatialunit() != null) {
			hashcode = hashcode + (int) getRelSpatialUnits1La_spatialunit().getORMID();
		}
		if (getRelSpatialUnits2La_spatialunit() != null) {
			hashcode = hashcode + (int) getRelSpatialUnits2La_spatialunit().getORMID();
		}
		return hashcode;
	}
	
	public String toString() {
		return super.toString();
	}
	
	private boolean _saved = false;
	
	public void onSave() {
		_saved=true;
	}
	
	
	public void onLoad() {
		_saved=true;
	}
	
	
	@Transient	
	public boolean isSaved() {
		return _saved;
	}
}
